package cn.easyutil.util.javaUtil.bean;

import java.util.Arrays;
import java.util.List;

/**
 * 文件类型枚举
 * @author spc
 *
 */
public enum FileTypeEnum {

	/** 
     * JPEG. 
     */  
    JPEG("FFD8FF","JPEG"),  
    
    /** 
     * JPG. 
     */  
    JPG("FFD8FF","JPG"),
  
    /** 
     * PNG. 
     */  
    PNG("89504E47","PNG"),
    
    /**
     * SVG
     */
    SVG("3c3f786d6c2076657273696f6e3d22312e302220656e636f64696e67","SVG"),
    
    /**
     * AI
     */
    AI("255044462d312e340d25e2e3cfd30d0a312030206f626a0d3c3c2f4d","AI"),
  
    /** 
     * GIF. 
     */  
    GIF("47494638","GIF"),  
  
    /** 
     * TIFF. 
     */  
    TIFF("49492A00","TIFF"),  
  
    /** 
     * Windows Bitmap. 
     */  
    BMP("424D","BMP"),  
  
    /** 
     * CAD. 
     */  
    DWG("41433130","DWG"),
  
    /** 
     * Adobe Photoshop. 
     */  
    PSD("38425053","PSD"),  
  
    /** 
     * Rich Text Format. 
     */  
    RTF("7B5C727466","RTF"),  
  
    /** 
     * XML. 
     */  
    XML("3C3F786D6C","XML"),  
  
    /** 
     * HTML. 
     */  
    HTML("68746D6C3E","HTML"),  
    /** 
     * CSS. 
     */  
    CSS("48544D4C207B0D0A0942","CSS"),  
    /** 
     * JS. 
     */  
    JS("696B2E71623D696B2E71","JS"),  
    /** 
     * Email [thorough only]. 
     */  
    EML("44656C69766572792D646174653A","EML"),  
  
    /** 
     * Outlook Express. 
     */  
    DBX("CFAD12FEC5FD746F","DBX"),  
  
    /** 
     * Outlook (pst). 
     */  
    PST("2142444E","PST"),  
  
    /** 
     * MS Word/Excel. 
     */  
    XLS("D0CF11E0","XLS"),
    
    DOC("D0CF11E0","DOC"),
    
    XLSX("504B030414000600080000002100","XLSX"),
    
    DOCX("504B030414000600080000002100","DOCX"),
    
    /** 
     * Visio 
     */  
    VSD("d0cf11e0a1b11ae10000","VSD"),  
    /** 
     * MS Access. 
     */  
    MDB("5374616E64617264204A","MDB"),  
    /** 
     * WPS文字wps、表格et、演示dps都是一样的 
     */  
    WPS("d0cf11e0a1b11ae10000","WPS"),  
    /** 
     * torrent 
     */  
    TORRENT("6431303A637265617465","TORRENT"),  
    /** 
     * WordPerfect. 
     */  
    WPD("FF575043","WPD"),  
  
    /** 
     * Postscript. 
     */  
    EPS("252150532D41646F6265","EPS"),  
  
    /** 
     * Adobe Acrobat. 
     */  
    PDF("255044462D312E","PDF"),  
  
    /** 
     * Quicken. 
     */  
    QDF("AC9EBD8F","QDF"),  
  
    /** 
     * Windows Password. 
     */  
    PWL("E3828596","PWL"),  
  
    /** 
     * ZIP Archive. 
     */  
    ZIP("504B0304","ZIP"),  
  
    /** 
     * RAR Archive. 
     */  
    RAR("52617221","RAR"),  
    /** 
     * JSP Archive. 
     */  
    JSP("3C2540207061676520","JSP"),  
    /** 
     * JAVA Archive. 
     */  
    JAVA("7061636B61676520","JAVA"),  
    /** 
     * CLASS Archive. 
     */  
    CLASS("CAFEBABE0000002E00","CLASS"),  
    /** 
     * JAR Archive. 
     */  
    JAR("504B03040A000000","JAR"),  
    /** 
     * MF Archive. 
     */  
    MF("4D616E69666573742D56","MF"),  
    /** 
     *EXE Archive. 
     */  
    EXE("4D5A9000030000000400","EXE"),  
    /** 
     *CHM Archive. 
     */  
    CHM("49545346030000006000","CHM"),  
    /* 
     * INI("235468697320636F6E66"), SQL("494E5345525420494E54"), BAT( 
     * "406563686F206f66660D"), GZ("1F8B0800000000000000"), PROPERTIES( 
     * "6C6F67346A2E726F6F74"), MXP( 
     * "04000000010000001300"), 
     */  
    /** 
     * Wave. 
     */  
    WAV("57415645","WAV"),  
  
    /** 
     * AVI. 
     */  
    AVI("41564920","AVI"),  
  
    /** 
     * Real Audio. 
     */  
    RAM("2E7261FD","RAM"),  
  
    /** 
     * Real Media. 
     */  
    RM("2E524D46","RM"),  
  
    /** 
     * MPEG (mpg). 
     */  
    MPG("000001BA","MPG"),  
  
    /** 
     * Quicktime. 
     */  
    MOV("6D6F6F76","MOV"),  
  
    /** 
     * Windows Media. 
     */  
    ASF("3026B2758E66CF11","ASF"),  
  
    /** 
     * MIDI. 
     */  
    MID("4D546864","MID"),  
    /** 
     * MP4. 
     */  
    MP4("00000020667479706d70","MP4"),
    
    /**
     * 未知视频格式
     */
    MP4_1("00000018667479706d70","MP4"),
    /** 
     * MP3. 
     */  
    MP3("49443303000000002176","MP3"),  
    /** 
     * FLV. 
     */  
    FLV("464C5601050000000900","FLV"),
	
    /**
     * 未知类型
     */
	UNKNOW(null,null);

	private String header;
	
	private String type;
	
	private FileTypeEnum(String header,String type){
		this.header = header;
		this.type = type;
	}

	public String getHeader() {
		return header;
	}

	public void setHeader(String header) {
		this.header = header;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
	
	/**
	 * 根据后缀名获取文件类型
	 * @param type
	 * @return
	 */
	public static FileTypeEnum getFileTypeByType(String type){
		FileTypeEnum[] values = FileTypeEnum.values();
		for (FileTypeEnum en : values) {
			if(en == UNKNOW){
				continue;
			}
			if(en.getType().equalsIgnoreCase(type)){
				return en;
			}
		}
		return UNKNOW;
	}
	
	/**
	 * 根据文件头获取文件类型
	 * @param type
	 * @return
	 */
	public static FileTypeEnum getFileTypeByHeader(String header){
		FileTypeEnum[] values = FileTypeEnum.values();
		for (FileTypeEnum en : values) {
			if(en == UNKNOW){
				continue;
			}
			if(header.toUpperCase().startsWith(en.getHeader().toUpperCase())){
				return en;
			}
		}
		return UNKNOW;
	}
	
	/**
	 * 获取所有图片类型
	 */
	public static List<FileTypeEnum> pictureTypes(){
		// 图片  
		FileTypeEnum[] pics = { FileTypeEnum.JPEG, FileTypeEnum.PNG, FileTypeEnum.GIF, FileTypeEnum.TIFF, FileTypeEnum.BMP, FileTypeEnum.DWG, FileTypeEnum.PSD ,FileTypeEnum.SVG};
        return Arrays.asList(pics);
	}
	
	/**
	 * 获取所有音频类型
	 */
	public static List<FileTypeEnum> audiosTypes(){
		FileTypeEnum[] audios = { FileTypeEnum.WAV, FileTypeEnum.MP3 };
		return Arrays.asList(audios);
	}
	
	/**
	 * 获取所有视频类型
	 * @return
	 */
	public static List<FileTypeEnum> videoTypes(){
		FileTypeEnum[] videos = { FileTypeEnum.AVI, FileTypeEnum.RAM, FileTypeEnum.RM, FileTypeEnum.MPG, FileTypeEnum.MOV, FileTypeEnum.ASF, FileTypeEnum.MP4, FileTypeEnum.FLV, FileTypeEnum.MID, FileTypeEnum.MP4_1};  
		return Arrays.asList(videos);
	}
	
	/**
	 * 获取所有文件类型
	 * @return
	 */
	public static List<FileTypeEnum> docTypes(){
		FileTypeEnum[] docs = { FileTypeEnum.RTF, FileTypeEnum.XML, FileTypeEnum.HTML, FileTypeEnum.CSS, FileTypeEnum.JS, FileTypeEnum.EML, FileTypeEnum.DBX, FileTypeEnum.PST, FileTypeEnum.XLS, FileTypeEnum.DOC, FileTypeEnum.XLSX, FileTypeEnum.DOCX, FileTypeEnum.VSD,  
                FileTypeEnum.MDB, FileTypeEnum.WPS, FileTypeEnum.WPD, FileTypeEnum.EPS, FileTypeEnum.PDF, FileTypeEnum.QDF, FileTypeEnum.PWL, FileTypeEnum.ZIP, FileTypeEnum.RAR, FileTypeEnum.JSP, FileTypeEnum.JAVA, FileTypeEnum.CLASS,  
                FileTypeEnum.JAR, FileTypeEnum.MF, FileTypeEnum.EXE, FileTypeEnum.CHM };
		return Arrays.asList(docs);
	}
}
